<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>商品管理管理</title>
	<meta name="decorator" content="default"/>
	<link rel="stylesheet" type="text/css" href="${ctxStatic}/ztree/css/demo.css">
	<link rel="stylesheet" type="text/css" href="${ctxStatic}/ztree/css/zTreeStyle/zTreeStyle.css">
	<script type="text/javascript" src="${ctxStatic}/ztree/js/jquery.ztree.all-3.5.js"></script>
	<script type="text/javascript" src="${ctxStatic}/ztree/js/jquery.ztree.core-3.5.js"></script>
	<link rel="stylesheet" type="text/css" href="${ctxStatic}/plupload/bootstrap.min.css">
	<script type="text/javascript" src="${ctxStatic}/plupload/plupload.full.min.js"></script>
	<script type="text/javascript" src="${ctxStatic}/ztree/js/jquery.ztree.excheck-3.5.js"></script>
	<style>
	#myModal {
	    position: fixed;
	    background: #fff;
	    left: 50%;
	    width: 310px;
	    height: 430px;
	    border: 5px solid #ddd;
	}
	.search {
		border: 1px solid #ddd;
	    width: 47px;
	    line-height: 16px;
	    height: 30px;
	}
	.search-input {
		width: 220px;
    	height: 30px !important;
	}
	.modal-header {
	    padding: 7px 22px;
	    border-bottom: 1px solid #e5e5e5;
	    font-weight: bold;
	    color: #333;
	    font-size: 18px;
	}
	.modal-footer {
		position: absolute;
	    bottom: 0;
	    width: 100%;
	}
	.btn-search {
	    background: url(images/jbox-button1.png) repeat-x transparent;
	    border: #aaa 1px solid;
	    color: #888;
	    border-radius: 3px 3px 3px 3px;
	    margin: 1px 7px 0 0;
	    height: 22px;
	    cursor: default;
	    padding: 0px 10px 0px 10px;
	}
	input {
		height: 30px !important;
	}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			var setting = {
				data:{
					simpleDate:{
						enable:true,
						idKey:'id',
						pIdKey:'parentId',
						rootPId:null
					}
				},
				async:{
					enable:true,
					url:"${ctx}/product/product/genProduct/ztree",
					autoParam:["id","name"],
					otherParam:{
						"otherParam":"zTreeAsyncTest"
					},
					dataFilter:function (treeId,parentNode,childNodes) {
						if (!childNodes) {
							return null;
						}
						for (var i=0;i<childNodes.length;i++) {
							childNodes[i].name=childNodes[i].name.replace(",");
						}
						return childNodes;
					}
					
				},
				callback:{
					onClick: function(treeId, treeNode) {  
					    var treeObj = $.fn.zTree.getZTreeObj(treeNode);  
					    var selectedNode = treeObj.getSelectedNodes()[0];
					    $(".right-search").attr("onclick",'treeRight("'+selectedNode.id+'","'+ selectedNode.name+'")')
					} 
				}	
			};
			$.fn.zTree.init($("#ultree"),setting);
			
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				},
				rules: {       
					code: {
				        required: true,
				     },
				     search: {
					        required: true,
					     },
				     name: {
				        required: true,
				     },
				     introduce: {
				        required: true,
				     },
				     brand: {
				        required: true,
				     },
				     nowprice: {
				        required: true,
				        number: true 
				     },
				     stock: {
				        required: true,
				        number: true 
				     },
				     /*暂时隐藏勿删*/
				     /*score: {
				        required: true,
				        number: true 
				     },*/
			    },
			  	messages: {
					code:  {
						required: "请输入货号",
					},
					search:  {
						required: "请选择分类",
					},
					name:  {
						required: "请输入商品名称",
					},
					introduce:  {
						required: "请输入简介",
					},
					brand:  {
						required: "请输入品牌",
					},
					nowprice:  {
						required: "请输入现货",
						number: "请输入数字格式",
					},
					stock:  {
						required: "请输入库存",
						number: "请输入数字格式",
					},
					/*暂时隐藏勿删*/
					/*score:  {
						required: "请输入赠送积分",
						 number: "请输入数字格式",
					},*/
			    }
			});
			
			$("#btnSubmit").click(function() {
				$("#inputForm").submit();
			});
			
		});
		function tissueParameters() {
			$("#catalogid2").val($("#catalogid").val());
			$("#name2").val($("#name").val());
			$("#order2").val($("#order1").val());
			$("#introduce2").val($("#introduce").val());
			$("#code2").val($("#code").val());
			$("#brand2").val($("#brand").val());
			$("#nowprice2").val($("#nowprice").val());
			$("#stock2").val($("#stock").val());
			$("#score2").val($("#score").val());
			$("#maxpicture2").val($("#maxpicture").val());
			$("#images2").val($("#images").val());
			$("#producthtml2").val($("#producthtml").val());
			$("#detail2").val($("#detail").val());
			$("#isnew2").val($('input[name="isnew"]:checked').val());
			$("#isrecommend2").val($('input[name="isrecommend"]:checked').val())
		}
		function associate() {
			tissueParameters();
			if ($("#catalogid2").val() == "") {
				alert("请选择分类！");
				return false;
			}
			
			$("#tabFrm").attr("action","${ctx}/product/product/genProduct/gif");
			$("#tabFrm").submit();
		}
		
		function form() {
			tissueParameters();
			$("#tabFrm").attr("action","${ctx}/product/product/genProduct/form");
			$("#tabFrm").submit();
		}
		
		function parameter() {
			tissueParameters();
			$("#tabFrm").attr("action","${ctx}/product/product/genProduct/parameter");
			$("#tabFrm").submit();
		}
		function picture() {
			tissueParameters();
			$("#tabFrm").attr("action","${ctx}/product/product/genProduct/picture");
			$("#tabFrm").submit();
		}
		function detail() {
			tissueParameters();
			$("#tabFrm").attr("action","${ctx}/product/product/genProduct/detail");
			$("#tabFrm").submit();
		}
		function hideShow(){
			$("#myModal").toggleClass("hide");
		}
		function treeRight(id,name){
	    	$("#catalogid").val(id);
		    $(".search-input").val(name);
		    hideShow()
	    }
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="#" onclick="form();">基本信息</a></li>
		<li ><a href="#" onclick="detail();">介绍</a></li>
		<li ><a href="#" onclick="picture();">商品图片</a></li>
		<li ><a href="#" onclick="parameter();">商品参数</a></li>
		<li ><a href="#" onclick="associate();">关联</a></li>
	</ul><br/>
	<spring:htmlEscape defaultHtmlEscape="true" />
	<form:form id="tabFrm" modelAttribute="genProduct" action="" method="post" htmlEscape="true">
		<form:hidden path="id"/>
		<form:hidden path="catalogid" id="catalogid2"/>
		<form:hidden path="name" id="name2"/>
		<form:hidden path="introduce" id="introduce2"/>
		<form:hidden path="code" id="code2"/>
		<form:hidden path="brand" id="brand2"/>
		<form:hidden path="nowprice" id="nowprice2"/>
		<form:hidden path="stock" id="stock2"/>
		<form:hidden path="score" id="score2"/>
		<form:hidden path="maxpicture" id="maxpicture2"/>
		<form:hidden path="images" id="images2"/>
		<form:hidden path="associateStr" id="associateStr2"/>
		<form:hidden path="producthtml" id="producthtml2" htmlEscape="true" />
		<form:hidden path="detail" id="detail2" htmlEscape="true" />
		<form:hidden path="isnew" id="isnew2"/>
		<form:hidden path="isrecommend" id="isrecommend2"/>
		<form:hidden path="order1" id="order2"/>
	</form:form>
	<form:form id="inputForm" modelAttribute="genProduct" action="${ctx}/product/product/genProduct/save" method="post" class="form-horizontal" htmlEscape="true">
		<form:hidden path="id"/>
		<form:hidden path="associateStr"/>
		<form:hidden path="maxpicture" id="maxpicture"/>
		<form:hidden path="images" id="images"/>
		<form:hidden path="producthtml" id="producthtml" htmlEscape="true" />
		<form:hidden path="detail" id="detail" htmlEscape="true" />
		<input type="hidden" id="sizes" name="sizes" value="" />
		<form:hidden path="catalogid" id="catalogid" class="input-xlarge required"/>
		
		<sys:message content="${message}"/>	
		<div class="control-group">
			<label class="control-label">分类：</label>
			<div class="controls">
				<div class="input-append">
					<input   class="required" type="hidden">
					<input name="search"   readonly="readonly" type="text"  data-msg-required="" class="required search-input" style="" value="${genProduct.catalogName }">
					<a onclick="hideShow()" class="btn search" >&nbsp;<i class="icon-search"></i>&nbsp;</a>&nbsp;&nbsp;
				</div>
				<div id="myModal" class="hide">
				  <div class="modal-header">
				    <button type="button" class="close" onclick="hideShow()">×</button>
				    <h3 id="myModalLabel">选择分类</h3>
				  </div>
				  <div class="modal-body">
				    <p><ul id="ultree" class="ztree"></ul></p>
				  </div>
				  <div class="modal-footer">
				  	<a class="btn btn-search right-search" onclick="treeRight()">确认</a>
				    <a class="btn btn-search" onclick="hideShow()">关闭</a>
				  </div>
				</div>
				<span class="help-inline"><font color="red">*</font></span>
			</div>
		</div>	
		<div class="control-group">
			<label class="control-label">商品名称：</label>
			<div class="controls">
				<form:input path="name" id="name" name="name" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">简介：</label>
			<div class="controls">
				<form:textarea path="introduce" id="introduce" name="introduce" htmlEscape="false" maxlength="500" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">排序：</label>
			<div class="controls">
				<form:input path="order1" id="order1" name="order1" htmlEscape="false" maxlength="64" class="input-xlarge digits required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">货号：</label>
			<div class="controls">
				<form:input path="code" id="code"  name="code" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">品牌：</label>
			<div class="controls">
				<form:input path="brand" id="brand" name="brand" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">现价：</label>
			<div class="controls">
				<form:input path="nowprice" id="nowprice" name="nowprice" htmlEscape="false" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">库存：</label>
			<div class="controls">
				<form:input path="stock" id="stock"  name="stock" htmlEscape="false" maxlength="11" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group hide">
			<label class="control-label">赠送积分：</label>
			<div class="controls">
				<form:input path="score"  id="score" name="score" htmlEscape="false" maxlength="11" value="0" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否是新品：</label>
			<div class="controls">
				<form:radiobutton path="isnew" value="n" checked="checked"/>否
				<form:radiobutton path="isnew" value="y"/>是
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否是推荐商品：</label>
			<div class="controls">
				<form:radiobutton path="isrecommend" value="n" checked="checked"/>否
				<form:radiobutton path="isrecommend" value="y"/>是
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="product:product:genProduct:edit"><input id="btnSubmit" class="btn btn-primary" type="button" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>